/*
 * @Author: your name
 * @Date: 2022-03-23 21:08:55
 * @LastEditTime: 2022-03-26 03:49:54
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \RVMDK（uv5）c:\Users\wangzhen\Desktop\张毕设\程序代码\毕设程序\Zigbee_Server\Components\zigbee\inc\zigbee.h
 */
#ifndef __ZIGBEE_CTRL_H
#define	__ZIGBEE_CTRL_H

#include "bsp_usart2.h"
#include "string.h"

/**
 * @brief 开启ZigBee客户端 [使能其一]
 */
#define ZIGBEE_CLIENT_ENABLE        (1)

/**
 * @brief 开启ZigBee服务端 [使能其一]
 */
//#define ZIGBEE_SERVER_ENABLE        (1)

/**
 * @brief 设备类型
 */
typedef enum {
    DEV_TYPE_COOR,          // 协调器
    DEV_TYPE_ROUTER,        // 路由器
    DEV_TYPE_END_DEV,       // 终端
    DEV_TYPE_MAX,
} ZigBee_DevType_t;

/**
 * @brief 网络状态
 */
typedef enum {
    NET_STATE_NULL, // 无网络
    NET_STATE_CONN, // 已连接
} ZigBee_NetState_t;


/**
 * @brief ZigBee信息;
 */
typedef struct {
    uint8_t  Mac[8];     // Mac 地址
    uint16_t ShortAddr;  // 设备短地址
} ZigBee_Property_t;

/**
 * @brief 数据发送;
 */
typedef struct {
    uint8_t dev_mac[8];     // 8 bytes
    uint8_t is_shake;       // 1: 震动; 0: 未震动
    uint8_t is_open;        // 1: 开;   0: 关
} ZigBee_Data_t;

/**
 * @brief 数据响应;
 */
typedef struct {
    uint8_t dev_mac[8];     // 8 bytes
    uint8_t shake_res;      // 1: 保存成功; 0: 保存失败
    uint8_t open_res;       // 1: 保存成功; 0: 保存失败
} ZigBee_Data_Ack_t;

void ZigBee_Init(void);

bsp_err_t ZigBee_Client_Start(void);
bsp_err_t ZigBee_Server_Start(void);

bsp_err_t ZigBee_Client_Reset(void);
bsp_err_t ZigBee_Server_Reset(void);

void ZigBee_Server_Data_Handle(void);
void ZigBee_Client_Upload_Handle(void);

bsp_err_t Client_Ping(uint32_t TimeToWait);

bsp_err_t ZigBee_Check(uint32_t TimeToWait);
bsp_err_t ZigBee_Reset(uint32_t TimeToWait);
bsp_err_t ZigBee_Restart(uint32_t TimeToWait);

bsp_err_t ZigBee_Set_DevType(ZigBee_DevType_t DevType, uint32_t TimeToWait);
bsp_err_t ZigBee_Get_DevType(ZigBee_DevType_t* DevType, uint32_t TimeToWait);

bsp_err_t ZigBee_Get_NetState(ZigBee_NetState_t* NetState, uint32_t TimeToWait);

bsp_err_t ZigBee_Set_PanID(uint16_t Pan_ID, uint32_t TimeToWait);
bsp_err_t ZigBee_Get_PanID(uint16_t* Pan_ID, uint32_t TimeToWait);

bsp_err_t ZigBee_Save_Enable(uint8_t Enable, uint32_t TimeToWait);

bsp_err_t ZigBee_Get_ShortAddr(uint16_t* ShortAddr, uint32_t TimeToWait);

bsp_err_t ZigBee_Get_Mac_Addr(uint8_t* Mac_Addr, uint8_t Len, uint32_t TimeToWait);

bsp_err_t ZigBee_Get_Coor_Mac_Addr(uint8_t* Coor_Mac_Addr, uint8_t Len, uint32_t TimeToWait);

bsp_err_t ZigBee_Get_Mac_ShortAddr(uint8_t* Mac_Addr, uint8_t Mac_Len, uint16_t* ShortAddr, uint32_t TimeToWait);


#endif /* __ZIGBEE_CTRL_H */
